package com.css.fxfzfxqh.modules.buildingIndividual.repository.impl;

import com.css.fxfzfxqh.constants.FxfzConstants;
import com.css.fxfzfxqh.modules.buildingIndividual.entity.BuildingIndividualEntity;
import com.css.fxfzfxqh.modules.buildingIndividual.repository.BuildingIndividualRepository;
import com.css.fxfzfxqh.modules.buildingIndividual.vo.ParamsVo;
import com.css.fxfzfxqh.modules.buildings.definitiveEvaluation.casualtiesDE.vo.PopulationBuildingIndividualVO;
import com.css.fxfzfxqh.modules.buildingKilometerGrid.model.param.QueryByVersionParam;
import com.css.fxfzfxqh.util.PlatformObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public class BuildingIndividualRepositoryImpl implements BuildingIndividualRepository {
    @Resource
    JdbcTemplate jdbcTemplate;
    @Resource
    NamedParameterJdbcTemplate namedParameterJdbcTemplate;

    @Override
    public boolean save(BuildingIndividualEntity buildingIndividualEntity) {
        String sql = "INSERT INTO fxqh_building_individual(id, building_code, province, province_id, city, city_id, county, county_id, longitude, latitude, structure_type1, structure_type2, defence_level, year, floors, usage1, usage2, area, address, floor_num, ext_wall_thickness, int_wall_thickness, floor_width, floor_length, total_floors, wall_section_area, land_type, height, floor_height, del_flag, create_name, create_user, create_time, update_name, update_user, update_time, data_version, townorcontry, geom,is_country_level) values(:id, :buildingCode, :province, :provinceId, :city, :cityId, :county, :countyId, :longitude, :latitude, :structureType1, :structureType2, :defenceLevel, :year, :floors, :usage1, :usage2, :area, :address, :floorNum, :extWallThickness, :intWallThickness, :floorWidth, :floorLength, :totalFloors, :wallSectionArea, :landType, :height, :floorHeight, :delFlag, :createName, :createUser, :createTime, :updateName, :updateUser, :updateTime, :dataVersion, :townorcontry, ST_GeometryFromText(:geom, 4490),:isCountryLevel)";
        SqlParameterSource source = new BeanPropertySqlParameterSource(buildingIndividualEntity);
        return namedParameterJdbcTemplate.update(sql, source) > 0;
    }

    @Override
    //public Map<String, Object> page(ParamsVo paramsVo, int curPage, int pageSize, String allRole, String provinceId) {
    public Map<String, Object> page(ParamsVo paramsVo, int curPage, int pageSize) {
        StringBuilder sql = new StringBuilder("select * from fxqh_building_individual ");
        StringBuilder whereSql = new StringBuilder(" where del_flag = '0'");
//        if (allRole.contains(FxfzConstants.YPG_PRI_GL_ROLE) || allRole.contains(FxfzConstants.YPG_PRI_YW_ROLE)) {//省级
//            whereSql.append(" and province_id = '" + provinceId + "'");
//        }
        if (!PlatformObjectUtils.isEmpty(paramsVo.getProvince())) {
            whereSql.append(" and province = '" + paramsVo.getProvince() + "'");
        }
        if (!PlatformObjectUtils.isEmpty(paramsVo.getCity())) {
            whereSql.append(" and city = '" + paramsVo.getCity() + "'");
        }
        if (!PlatformObjectUtils.isEmpty(paramsVo.getCounty())) {
            whereSql.append(" and county = '" + paramsVo.getCounty() + "'");
        }
        if (!PlatformObjectUtils.isEmpty(paramsVo.getStructureType1())) {
            whereSql.append(" and structure_type1 = '" + paramsVo.getStructureType1() + "'");
        }
        if (!PlatformObjectUtils.isEmpty(paramsVo.getStructureType2())) {
            whereSql.append(" and structure_type2 = '" + paramsVo.getStructureType2() + "'");
        }
        if (!PlatformObjectUtils.isEmpty(paramsVo.getDefenceLevel())) {
            whereSql.append(" and defence_level = '" + paramsVo.getDefenceLevel() + "'");
        }
        if (!PlatformObjectUtils.isEmpty(paramsVo.getYear())) {
            whereSql.append(" and year = '" + paramsVo.getYear() + "'");
        }
        if (!PlatformObjectUtils.isEmpty(paramsVo.getFloors())) {
            whereSql.append(" and floors = '" + paramsVo.getFloors() + "'");
        }
        if (!PlatformObjectUtils.isEmpty(paramsVo.getVersionCode())) {
            whereSql.append(" and data_version = '" + paramsVo.getVersionCode() + "'");
        }
        StringBuilder orderSql = new StringBuilder(" order by create_time desc");
        int firstIndex = (curPage - 1) * pageSize;
        int lastIndex = pageSize;
        StringBuilder limitSql = new StringBuilder(" limit " + lastIndex + " offset " + firstIndex);
        sql.append(whereSql).append(orderSql);
        Integer total = jdbcTemplate.query(sql.toString(), new BeanPropertyRowMapper<>(BuildingIndividualEntity.class)).size();
        List<BuildingIndividualEntity> samplingData = jdbcTemplate.query(sql.append(limitSql).toString(), new BeanPropertyRowMapper<>(BuildingIndividualEntity.class));
        Map<String, Object> map = new HashMap();
        map.put("total", total);
        map.put("rows", samplingData);
        return map;
    }

    @Override
    public Map<String, Object> getVersion(ParamsVo paramsVo, int curPage, int pageSize, String allRole, String provinceId) {
        StringBuilder sql = new StringBuilder("select data_version from fxqh_building_individual ");
        StringBuilder whereSql = new StringBuilder(" where del_flag = '0'");
        if (allRole.contains(FxfzConstants.YPG_PRI_GL_ROLE) || allRole.contains(FxfzConstants.YPG_PRI_YW_ROLE)) {//省级
            whereSql.append(" and province_id = '" + provinceId + "'");
        }
        if (!PlatformObjectUtils.isEmpty(paramsVo.getProvinceId())) {
            whereSql.append(" and province_id = '" + paramsVo.getProvinceId() + "'");
        }
        if (!PlatformObjectUtils.isEmpty(paramsVo.getCityId())) {
            whereSql.append(" and city_id = '" + paramsVo.getCityId() + "'");
        }
        if (!PlatformObjectUtils.isEmpty(paramsVo.getCountyId())) {
            whereSql.append(" and county_id = '" + paramsVo.getCountyId() + "'");
        }
        if (!PlatformObjectUtils.isEmpty(paramsVo.getStructureType1())) {
            whereSql.append(" and structure_type1 = '" + paramsVo.getStructureType1() + "'");
        }
        if (!PlatformObjectUtils.isEmpty(paramsVo.getStructureType2())) {
            whereSql.append(" and structure_type2 = '" + paramsVo.getStructureType2() + "'");
        }
        if (!PlatformObjectUtils.isEmpty(paramsVo.getDefenceLevel())) {
            whereSql.append(" and defence_level = '" + paramsVo.getDefenceLevel() + "'");
        }
        if (!PlatformObjectUtils.isEmpty(paramsVo.getYear())) {
            whereSql.append(" and year = '" + paramsVo.getYear() + "'");
        }
        if (!PlatformObjectUtils.isEmpty(paramsVo.getFloors())) {
            whereSql.append(" and floors = '" + paramsVo.getFloors() + "'");
        }
        whereSql.append(" group by data_version ");
        int firstIndex = (curPage - 1) * pageSize;
        int lastIndex = pageSize;
        StringBuilder limitSql = new StringBuilder(" limit " + lastIndex + " offset " + firstIndex);
        sql.append(whereSql);
        Integer total = jdbcTemplate.query(sql.toString(), new BeanPropertyRowMapper<>(BuildingIndividualEntity.class)).size();
        List<BuildingIndividualEntity> samplingData = jdbcTemplate.query(sql.append(limitSql).toString(), new BeanPropertyRowMapper<>(BuildingIndividualEntity.class));
        Map<String, Object> map = new HashMap();
        map.put("total", total);
        map.put("rows", samplingData);
        return map;
    }

    @Override
    public boolean update(BuildingIndividualEntity buildingIndividualEntity) {
        String sql = "update fxqh_building_individual set building_code=:buildingCode,province=:province,province_id=:provinceId,city=:city,city_id=:cityId,county=:county,county_id=:countyId," +
                "longitude=:longitude,latitude=:latitude,structure_type1=:structureType1,structure_type2=:structureType2,defence_level=:defenceLevel," +
                "year=:year,floors=:floors,usage1=:usage1,usage2=:usage2,area=:area,address=:address,floor_num=:floorNum,ext_wall_thickness=:extWallThickness," +
                "int_wall_thickness=:intWallThickness,floor_width=:floorWidth,floor_length=:floorLength,total_floors=:totalFloors,wall_section_area=:wallSectionArea," +
                "land_type=:landType,height=:height,floor_Height=:floorHeight,update_name=:updateName,update_user=:updateUser,update_time=:updateTime" +
                ",townorcontry=:townorcontry where id='" + buildingIndividualEntity.getId() + "'";
        SqlParameterSource source = new BeanPropertySqlParameterSource(buildingIndividualEntity);
        return namedParameterJdbcTemplate.update(sql, source) > 0;
    }

    @Override
    public boolean delete(String id) {
        String sql = "update fxqh_building_individual set del_flag = '1' where id = ?";
        return jdbcTemplate.update(sql, id) > 0;
    }

    @Override
    public BuildingIndividualEntity findById(String id) {
        String sql = "select * from fxqh_building_individual where del_flag = '0' and id = ?";
        try {
            BuildingIndividualEntity buildingIndividualEntity = jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<>(BuildingIndividualEntity.class), id);
            return buildingIndividualEntity;
        } catch (EmptyResultDataAccessException e) {
            return null;
        }
    }

    @Override
    public List<BuildingIndividualEntity> findAll(String version) {
        String sql = "select * from fxqh_building_individual where del_flag = '0' and data_version='" + version + "' and del_flag='0'";
        return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(BuildingIndividualEntity.class));
    }

    @Override
    public List<BuildingIndividualEntity> findAll1(QueryByVersionParam param) {
        StringBuilder sql = new StringBuilder("select * from fxqh_building_individual where del_flag = '0' and data_version='" + param.getVersionCode() + "' and del_flag='0'");
        if (param.getGeomType() != null && 1 == param.getGeomType()) {
            sql.append(" and st_intersects(st_geometryfromtext('POINT(' || longitude || ' ' || latitude || ')',4490),st_geomFromText('").append(param.getGeom()).append("',4490))");
        } else {
            if (org.apache.commons.lang3.StringUtils.isNotBlank(param.getProvince())) {
                sql.append(" and province = '").append(param.getProvince()).append("' ");
            }
            if (org.apache.commons.lang3.StringUtils.isNotBlank(param.getCity())) {
                sql.append(" and city = '").append(param.getCity()).append("' ");
            }
            if (StringUtils.isNotBlank(param.getCounty())) {
                sql.append(" and county = '").append(param.getCounty()).append("' ");
            }
        }
        if (PlatformObjectUtils.isNotEmpty(param.getVersionCode())){
            if ("0".equals(param.getVersionCode())){
                sql.append(" and is_country_level='0'");
            }else {
                //0国家级管理员  1省级管理员  2市级管理员  3县级管理员
                if ("1".equals(param.getRole())){
                    sql.append(" and province_id = '").append(param.getLevel()).append("' ");
                }else if ("2".equals(param.getRole())){
                    sql.append(" and city_id = '").append(param.getLevel()).append("' ");
                }else if ("3".equals(param.getRole())){
                    sql.append(" and county_id = '").append(param.getLevel()).append("' ");
                }
            }
        }
        sql.append(" order by county  desc ");
        return jdbcTemplate.query(sql.toString(), new BeanPropertyRowMapper<>(BuildingIndividualEntity.class));
    }

    @Override
    public List<PopulationBuildingIndividualVO> getAllWithGeomAndArea(String geom, String version, String province, String city, String county) {
        String sql = "SELECT building_code,CAST(area as decimal)  from fxqh_building_individual where del_flag='0' and data_version='" + version + "'" +
                " and ST_Intersects(st_geometryfromtext(st_astext('" + geom + "'),4490)," +
                " st_geometryfromtext('POINT(' || longitude || ' ' || latitude || ')',4490)) ";
        if(StringUtils.isNotBlank(province)){
            sql += " and province='" + province + "'";
        }
        if(StringUtils.isNotBlank(city)){
            sql += " and city='" + city + "' ";
        }
        if(StringUtils.isNotBlank(county)){
            sql += " and county='" + county + "' ";
        }
        return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(PopulationBuildingIndividualVO.class));
    }

    @Override
    public List<BuildingIndividualEntity> getAllWithGeom(String houseData, String geom, String province, String city, String county) {
        String sql = "SELECT *  from fxqh_building_individual where data_version='" + houseData + "' and province='" + province + "' and city='" + city + "' and county='" + county + "' and del_flag='0'";
        if (StringUtils.isNotBlank(geom)) {
            sql += (" and ST_Intersects(st_geometryfromtext(st_astext('" + geom + "'),4490),st_geometryfromtext('POINT(' || longitude || ' ' || latitude || ')',4490)) ");
        }
        return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(BuildingIndividualEntity.class));
    }

    @Override
    public List<BuildingIndividualEntity> queryYwData(QueryByVersionParam param) {
        StringBuilder sql = new StringBuilder("select *,ST_AsText(geom) geomText from fxqh_building_individual ");
        StringBuilder whereSql = new StringBuilder(" where del_flag = '0' and data_version = '" + param.getVersionCode() + "'");
        if (PlatformObjectUtils.isNotEmpty(param.getGeomType()) && 1 == param.getGeomType()) {
            whereSql.append(" and st_intersects(st_geometryfromtext('" + param.getGeom() + "',4490),st_geometryfromtext('POINT(' ||" +
                    " longitude || ' ' || latitude || ')',4490))");
        } else {
            if (PlatformObjectUtils.isNotEmpty(param.getProvince())) {
                whereSql.append(" and province = '" + param.getProvince() + "' ");
            }
            if (PlatformObjectUtils.isNotEmpty(param.getCity())) {
                whereSql.append(" and city = '" + param.getCity() + "' ");
            }
            if (PlatformObjectUtils.isNotEmpty(param.getCounty())) {
                whereSql.append(" and county = '" + param.getCounty() + "' ");
            }
        }
        return jdbcTemplate.query(sql.append(whereSql).toString(), new BeanPropertyRowMapper<>(BuildingIndividualEntity.class));
    }

    //地震影响场相交房屋单体
    @Override
    public List<BuildingIndividualEntity> queryALLByInfluence(QueryByVersionParam param) {
        StringBuilder sql = new StringBuilder("SELECT t.* FROM (select * from fxqh_building_individual");
        StringBuilder whereSql = new StringBuilder(" where del_flag = '0' ");
        if (PlatformObjectUtils.isNotEmpty(param.getGeomType()) && 1 == param.getGeomType()) {
            whereSql.append(" and st_intersects(st_geometryfromtext('" + param.getGeom() + "',4490),st_geometryfromtext('POINT(' ||" +
                    " longitude || ' ' || latitude || ')',4490))");
        } else {
            if (PlatformObjectUtils.isNotEmpty(param.getProvince())) {
                whereSql.append(" and province = '" + param.getProvince() + "' ");
            }
            if (PlatformObjectUtils.isNotEmpty(param.getCity())) {
                whereSql.append(" and city = '" + param.getCity() + "' ");
            }
            if (PlatformObjectUtils.isNotEmpty(param.getCounty())) {
                whereSql.append(" and county = '" + param.getCounty() + "' ");
            }
        }
        if (PlatformObjectUtils.isNotEmpty(param.getVersionCode())) {
            whereSql.append(" and data_version = '" + param.getVersionCode() + "') t ");
        }
        whereSql.append("WHERE ST_Intersects(st_geometryfromtext('POINT(' || t.longitude || ' ' || t.latitude || ')',4490),(select a.geom FROM fxqh_setting_seismic_influenceflied a WHERE a.del_flag = '0' and a.id = '" + param.getField() + "'))");
        return jdbcTemplate.query(sql.append(whereSql).toString(), new BeanPropertyRowMapper<>(BuildingIndividualEntity.class));
    }

    //四个概率LD相交房屋单体
    @Override
    public List<BuildingIndividualEntity> getAllByLD(QueryByVersionParam param) {
        StringBuilder sql = new StringBuilder("SELECT a.*,b.ld50year63 as year50ProExceedance063,b.ld50year10 as year50ProExceedance010,b.ld50year2 as year50ProExceedance002,b.ld100year1 as year100ProExceedance001 " +
                " FROM (select * from fxqh_building_individual  where del_flag='0'");
        if (PlatformObjectUtils.isNotEmpty(param.getGeomType()) && 1 == param.getGeomType()) {
            sql.append(" and st_intersects(st_geometryfromtext('" + param.getGeom() + "',4490)," +
                    "st_geometryfromtext('POINT(' || longitude || ' ' || latitude || ')',4490))");
        } else {
            if (PlatformObjectUtils.isNotEmpty(param.getProvince())) {
                sql.append(" and province = '" + param.getProvince() + "' ");
            }
            if (PlatformObjectUtils.isNotEmpty(param.getCity())) {
                sql.append(" and city = '" + param.getCity() + "' ");
            }
            if (PlatformObjectUtils.isNotEmpty(param.getCounty())) {
                sql.append(" and county = '" + param.getCounty() + "' ");
            }
        }
        sql.append(" and data_version='" + param.getVersionCode() + "' )a ");
        sql.append(" left join " +
                " (select * from jc_ld where assess_id ='" + param.getAssessId() + "')b " +
                " on 1=1 " +
                " where st_intersects(b.geom,st_geometryfromtext('POINT(' || a.longitude || ' ' || a.latitude || ')',4490))");
        return jdbcTemplate.query(sql.toString(), new BeanPropertyRowMapper<>(BuildingIndividualEntity.class));
    }

    //四个概率PGA相交房屋单体
    @Override
    public List<BuildingIndividualEntity> getAllByPGA(QueryByVersionParam param) {
        StringBuilder sql = new StringBuilder("SELECT a.*,b.pga50year63 as year50ProExceedance063,b.pga50year10 as year50ProExceedance010,b.pga50year2 as year50ProExceedance002,b.pga100year1 as year100ProExceedance001 " +
                "FROM (select * from fxqh_building_individual  where del_flag='0' " );
        if (PlatformObjectUtils.isNotEmpty(param.getGeomType()) && 1 == param.getGeomType()) {
            sql.append(" and st_intersects(st_geometryfromtext('" + param.getGeom() + "',4490)," +
                    "st_geometryfromtext('POINT(' || longitude || ' ' || latitude || ')',4490))");
        } else {
            if (PlatformObjectUtils.isNotEmpty(param.getProvince())) {
                sql.append(" and province = '" + param.getProvince() + "' ");
            }
            if (PlatformObjectUtils.isNotEmpty(param.getCity())) {
                sql.append(" and city = '" + param.getCity() + "' ");
            }
            if (PlatformObjectUtils.isNotEmpty(param.getCounty())) {
                sql.append(" and county = '" + param.getCounty() + "' ");
            }
        }
        sql.append(" and data_version='" + param.getVersionCode() + "' )a ");
        sql.append(" left join " +
                " (select * from jc_pga where assess_id ='" + param.getAssessId() + "')b " +
                " on 1=1 " +
                " where st_intersects(b.geom,st_geometryfromtext('POINT(' || a.longitude || ' ' || a.latitude || ')',4490))");
        return jdbcTemplate.query(sql.toString(), new BeanPropertyRowMapper<>(BuildingIndividualEntity.class));
    }

    @Override
    public List<BuildingIndividualEntity> queryDataByParam1(QueryByVersionParam param) {
        String sql = "select a.*,b.dz_intensity intensity" +
                " from (select * from fxqh_building_individual where del_flag = '0' and data_version = '" + param.getVersionCode() + "'";

        if (PlatformObjectUtils.isNotEmpty(param.getGeomType()) && 1 == param.getGeomType()) {
            sql = sql + (" and st_intersects(st_geometryfromtext('" + param.getGeom() + "',4490),st_geometryfromtext('POINT(' ||" +
                    " longitude || ' ' || latitude || ')',4490))");
        } else {
            if (PlatformObjectUtils.isNotEmpty(param.getProvince())) {
                sql = sql + (" and province = '" + param.getProvince() + "' ");
            }
            if (PlatformObjectUtils.isNotEmpty(param.getCity())) {
                sql = sql + (" and city = '" + param.getCity() + "' ");
            }
            if (PlatformObjectUtils.isNotEmpty(param.getCounty())) {
                sql = sql + (" and county = '" + param.getCounty() + "' ");
            }
        }
        sql = sql + ") a,(select dz_intensity,geom from fxqh_setting_seismic_influenceflied where version_code = '" + param.getInfluenceVersion() + "' and del_flag='0') b" +
                " where st_intersects(ST_GeometryFromText('point('||a.longitude||' '||a.latitude||')', 4490),b.geom)";
        return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(BuildingIndividualEntity.class));
    }

    @Override
    public List<BuildingIndividualEntity> findByOnlyOneCondition(BuildingIndividualEntity buildingIndividualEntity) {
        try {
            String sql = "select * from fxqh_building_individual where province = ? and city = ? and county = ? and longitude = ? and latitude = ? and structure_type1 = ? and structure_type2=? and del_flag = '0'";
            return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(BuildingIndividualEntity.class), buildingIndividualEntity.getProvince(), buildingIndividualEntity.getCity(), buildingIndividualEntity.getCounty(), buildingIndividualEntity.getLongitude().toString(), buildingIndividualEntity.getLatitude().toString(), buildingIndividualEntity.getStructureType1(), buildingIndividualEntity.getStructureType2());
        } catch (EmptyResultDataAccessException e) {
            return null;
        }
    }

    @Override
    public Map<String, Object> queryBuildingMap(ParamsVo paramsVo, String allRole, String provinceId) {
        StringBuilder sql = new StringBuilder("select * from fxqh_building_individual ");
        StringBuilder whereSql = new StringBuilder(" where del_flag = '0'");
        if (allRole.contains(FxfzConstants.YPG_PRI_GL_ROLE) || allRole.contains(FxfzConstants.YPG_PRI_YW_ROLE)) {//省级
            whereSql.append(" and province = '" + provinceId + "'");
        }
        if (!PlatformObjectUtils.isEmpty(paramsVo.getProvinceId())) {
            whereSql.append(" and province = '" + paramsVo.getProvinceId() + "'");
        }
        if (!PlatformObjectUtils.isEmpty(paramsVo.getCityId())) {
            whereSql.append(" and city = '" + paramsVo.getCityId() + "'");
        }
        if (!PlatformObjectUtils.isEmpty(paramsVo.getCountyId())) {
            whereSql.append(" and county = '" + paramsVo.getCountyId() + "'");
        }
        if (!PlatformObjectUtils.isEmpty(paramsVo.getStructureType1())) {
            whereSql.append(" and structure_type1 = '" + paramsVo.getStructureType1() + "'");
        }
        if (!PlatformObjectUtils.isEmpty(paramsVo.getStructureType2())) {
            whereSql.append(" and structure_type2 = '" + paramsVo.getStructureType2() + "'");
        }
        if (!PlatformObjectUtils.isEmpty(paramsVo.getDefenceLevel())) {
            whereSql.append(" and defence_level = '" + paramsVo.getDefenceLevel() + "'");
        }
        if (!PlatformObjectUtils.isEmpty(paramsVo.getYear())) {
            whereSql.append(" and year = '" + paramsVo.getYear() + "'");
        }
        if (!PlatformObjectUtils.isEmpty(paramsVo.getFloors())) {
            whereSql.append(" and floors = '" + paramsVo.getFloors() + "'");
        }
        if (!PlatformObjectUtils.isEmpty(paramsVo.getVersionCode())) {
            whereSql.append(" and data_version = '" + paramsVo.getVersionCode() + "'");
        }
        StringBuilder orderSql = new StringBuilder(" order by create_time desc");
        sql.append(whereSql).append(orderSql);
        Integer total = jdbcTemplate.query(sql.toString(), new BeanPropertyRowMapper<>(BuildingIndividualEntity.class)).size();
        List<BuildingIndividualEntity> samplingData = jdbcTemplate.query(sql.toString(), new BeanPropertyRowMapper<>(BuildingIndividualEntity.class));
        Map<String, Object> map = new HashMap();
        map.put("total", total);
        map.put("rows", samplingData);
        return map;
    }
}
